<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;

abstract  class BaseController extends Controller {
    public $pagesize = 10;

    protected $httpStatus = 200;
    protected $bizCode    = 10000;

    public function respond($status, $message, $addtion)
    {

        $data = [
            'message' => $message,
            'code' => $this->bizCode
        ];

        if( ! empty($addtion)) {
            $data = array_merge($data, $addtion);
        }

        return response([$status => $data], $this->httpStatus);
    }

    public function responseCreatedSuccess($message, $addtion = [])
    {
        $this->httpStatus = 201;
        return $this->respond('success', $message, $addtion);
    }

    public function responseCreatedFail($message, $addtion = [])
    {
        $this->httpStatus = 422;
        return $this->respond('error', $message, $addtion);
    }

    public function responseUpdatedSuccess($message, $addtion)
    {
        return $this->respond('success', $message, $addtion);
    }

    public function responseUpdatedFail($message, $addtion = [])
    {
        $this->httpStatus = 422;
        return $this->respond('error', $message, $addtion);
    }

    public function responseDeletedSuccess($message, $addtion)
    {
        return $this->respond('success', $message, $addtion);
    }

    public function responseDeletedFail($message, $addtion = [])
    {
        $this->httpStatus = 422;
        return $this->respond('error', $message, $addtion);
    }
}